package com.fourth.shopping.service.impl;

import com.fourth.entity.Goods;
import com.fourth.entity.Item;
import com.fourth.shopping.dto.GoodsTableSearch;
import com.fourth.shopping.dao.GoodsMapper;
import com.fourth.shopping.dao.ItemMapper;
import com.fourth.shopping.service.GoodsService;
import com.fourth.vo.PageCondition;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

@Service
public class GoodsServiceImpl implements GoodsService {
    @Resource
    private GoodsMapper goodsMapper;
    @Resource
    private ItemMapper itemMapper;

    @Override
    public List<GoodsTableSearch> getGoodsByLimit(Goods goods, PageCondition condition) {
        List<Goods> goodsByLimit = goodsMapper.getGoodsByLimit(goods, condition);
        List<GoodsTableSearch> goodsTableDate = new ArrayList<>();
        for (Goods goods1 : goodsByLimit) {
            if (goods1 != null) {
                System.out.println("itemMapper:"+itemMapper.getItemType(goods1.getGoodsId()));
                goodsTableDate.add(new GoodsTableSearch(itemMapper.getItemType(goods1.getGoodsId()), goods1));
            }
        }

        System.out.println(goodsTableDate);
        return goodsTableDate;
    }

    @Override
    public Integer getGoodsCountByGoodId(Goods goods) {
        return goodsMapper.getGoodsCountByLimit(goods);
    }

    @Override
    public Integer deleteGoods(String goodsId) {
        return goodsMapper.deleteGoods(goodsId);
    }

    @Override
    public List<Item> getGoodsAllType() {
        return itemMapper.getAllType();
    }

    @Override
    public Integer addGoods(Goods goods) {
        Date date = new Date();
        goods.setCreateTime(date);
        goods.setUpdateTime(date);
        goods.setStatus("1");

        System.out.println("文件上传商品信息："+goods);


        return  goodsMapper.addGoods(goods);
    }

}
